package service;
import java.util.List;




import javax.annotation.Resource;

import mapper.SysFuncRepository;
import mapper.SysRoleRepository;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import common.BaseService;
import entity.SysFunc;
import entity.SysRole;

@Service
@Import(BaseService.class)
public class SysRoleService  extends BaseService<SysRole,SysRoleRepository>{
	
	private static Logger logger = Logger.getLogger(SysRoleService.class);  

	@Autowired
   private SysRoleRepository sysRoleRepository;
	 
    @RequestMapping("save")
    public  String save(SysRole sysRole){
    	if((sysRole.getSeqid()==null || sysRole.getSeqid()==0L)){
    		sysRoleRepository.insert(sysRole);
		}else{
			//save方法表示当实体存在的时候就更新，不存在则插入。但是插入的效率低于insert
			logger.info(sysRoleRepository.updateById(sysRole));
		}
       return "ok";
    }
    
    @RequestMapping("insert")
    public  String insert(SysRole sysRole){
    	sysRoleRepository.insert(sysRole);
       return "ok";
    }
   
    @RequestMapping("find")
    public List<SysRole> find(){
    	List<SysRole> SysRoleList = sysRoleRepository.all();
       return SysRoleList;
       
    }
   
    @RequestMapping("findByName")
    public SysRole findByName(){
       return sysRoleRepository.findRoleByName("张三");
    }
    
    @RequestMapping("findById")
    public SysRole findById(long seqid){
    	SysRole sysRole = sysRoleRepository.findById(seqid);
       return sysRole;
    }
    
    @RequestMapping("deleteByIds")
    public void deleteByIds(String [] seqids){
    	for(int i=0;i<seqids.length;i++){
    		sysRoleRepository.deleteForId(Long.parseLong(seqids[i]));
//			 Query query = new Query();  
//			 query.addCriteria(Criteria.where("_id").is(seqids[i]));  
//    		 mongoTemplate.remove(query, SysRole.class);
    	}
    }
	
	
    
}

